package com.zmn.plat.dubbo.impl.push;

import javax.annotation.Resource;

import org.apache.dubbo.config.annotation.Service;

import com.alibaba.fastjson.JSONObject;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.plat.business.interfaces.push.ZmnSmsBService;
import com.zmn.plat.common.exception.PlatException;
import com.zmn.plat.dubbo.dto.sendtemplate.SendSmsDIO;
import com.zmn.plat.dubbo.interfaces.push.ZmnSmsRemoteService;
import com.zmn.plat.dubbo.utils.DubboConsts;

import lombok.extern.slf4j.Slf4j;

/**
 * 描述：zmn 通知信息发送接口实现类
 *
 * @author wangjie
 * @since 2020/6/22 9:55
 **/
@Slf4j
@Service(timeout = 8000, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class ZmnSmsRemoteServiceImpl implements ZmnSmsRemoteService {

    @Resource
    ZmnSmsBService zmnSmsBService;

    @Override
    @ReadOnlyConnection
    public ResponseDTO<Boolean> sendSmsInfo(SendSmsDIO sendSmsDio) {
        log.info("[{}],发送模板消息转化前入参，msg:{}", "发送模板消息", JSONObject.toJSONString(sendSmsDio));

        try {
            Boolean b = zmnSmsBService.sendSmsInfo(sendSmsDio);
            return ResponseDTO.success(b);
        } catch (PlatException e) {
            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
        } catch (Exception e) {
            log.error("sendSmsInfo error.sendSmsDio={}", sendSmsDio, e);
            return ResponseDTO.fail(GlobalConsts.FAILD_MSG);
        }
    }

}
